import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:getx_example/get_lazy_put/controller/my_lzay_put_controller.dart';
import 'package:getx_example/get_view/my_get_view_page.dart';

class MyLazyPutPage extends StatelessWidget {
  static const String route = "/MyLazyPutPage";
  const MyLazyPutPage({super.key});

  @override
  Widget build(BuildContext context) {
    final MyGetLazyPutController getLazyPutController = Get.find<MyGetLazyPutController>();

    return Scaffold(
      appBar: AppBar(title: const Text("Getx_Getx"), actions: [
        IconButton(
          icon: const Icon(Icons.refresh),
          onPressed: () {
            getLazyPutController.updateAll();
          },
        )
      ]),
      body: SingleChildScrollView(
          child: Column(
        children: [
          Card(
            margin: const EdgeInsets.only(left: 20, right: 20, bottom: 10, top: 10),
            child: ListTile(
              title: const Text("当验证 Get. GetView"),
              subtitle: const Text(" Get.to(const MyGetViewPage())"),
              leading: const Icon(Icons.home),
              trailing: const Icon(Icons.arrow_forward_ios),
              onTap: () {
                Get.to(const MyGetViewPage());
              },
            ),
          ),
          Card(
            margin: const EdgeInsets.only(left: 20, right: 20, bottom: 10, top: 10),
            child: ListTile(
              title: const Text("update Count"),
              subtitle: GetX<MyGetLazyPutController>(
                  init: getLazyPutController,
                  initState: (_) {
                    debugPrint("initState");
                  },
                  builder: (_) {
                    return Column(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        Text('count = ${getLazyPutController.count.value}'),
                        Text('count = ${getLazyPutController.count1.value}'),
                      ],
                    );
                  }),
              onTap: () {
                getLazyPutController.updateCount();
              },
            ),
          ),
          Card(
            margin: const EdgeInsets.only(left: 20, right: 20, bottom: 10, top: 10),
            child: ListTile(
              title: const Text("update String "),
              subtitle: GetX<MyGetLazyPutController>(
                init: getLazyPutController,
                initState: (_) {},
                builder: (_) {
                  return Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Text('我要买${getLazyPutController.audi.value}'),
                      Text('我要买${getLazyPutController.audi.value}'),
                    ],
                  );
                },
              ),
              onTap: () {
                getLazyPutController.updateAudi();
              },
            ),
          ),
          Card(
            margin: const EdgeInsets.only(left: 20, right: 20, bottom: 10, top: 10),
            child: ListTile(
              title: const Text("update list"),
              subtitle: GetX<MyGetLazyPutController>(
                init: getLazyPutController,
                initState: (_) {},
                builder: (_) {
                  return Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Text('我要买${getLazyPutController.list.toString()}'),
                      Text('我要买${getLazyPutController.list1.toString()}'),
                    ],
                  );
                },
              ),
              onTap: () {
                //list, 要修改list里面的元素, 才会去更新UI
                getLazyPutController.updateList();
              },
            ),
          ),
          Card(
            margin: const EdgeInsets.only(left: 20, right: 20, bottom: 10, top: 10),
            child: ListTile(
              title: const Text("update map"),
              subtitle: GetX<MyGetLazyPutController>(
                init: getLazyPutController,
                initState: (_) {},
                builder: (_) {
                  return Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Text('我要买${getLazyPutController.map.toString()}'),
                      Text('我要买${getLazyPutController.map1.toString()}'),
                    ],
                  );
                },
              ),
              onTap: () {
                getLazyPutController.updateMap();
              },
            ),
          ),
          Card(
            margin: const EdgeInsets.only(left: 20, right: 20, bottom: 10, top: 10),
            child: ListTile(
              title: const Text("update updateModels"),
              subtitle: GetX<MyGetLazyPutController>(
                  init: getLazyPutController,
                  initState: (_) {},
                  builder: (_) {
                    return Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
                      const Text("data: getLazyPutController.models",
                          style: TextStyle(color: Colors.black, fontSize: 20, fontWeight: FontWeight.bold)),
                      Column(
                          crossAxisAlignment: CrossAxisAlignment.start,
                          children: getLazyPutController.models.map((element) {
                            return Text('我要买${element.name}');
                          }).toList()),
                      const Text("data: getLazyPutController.models1",
                          style: TextStyle(color: Colors.black, fontSize: 20, fontWeight: FontWeight.bold)),
                      Column(
                          crossAxisAlignment: CrossAxisAlignment.start,
                          children: getLazyPutController.models1.map((element) {
                            return Text('我要买${element.name}');
                          }).toList()),
                    ]);
                  }),
              onTap: () {
                getLazyPutController.updateModels();
              },
            ),
          ),
          Card(
            margin: const EdgeInsets.only(left: 20, right: 20, bottom: 10, top: 10),
            child: ListTile(
              title: const Text("update updateRxModels"),
              subtitle: GetX<MyGetLazyPutController>(
                  init: getLazyPutController,
                  initState: (_) {},
                  builder: (_) {
                    return Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
                      const Text("data: getLazyPutController.rxModels",
                          style: TextStyle(color: Colors.black, fontSize: 20, fontWeight: FontWeight.bold)),
                      Column(
                          crossAxisAlignment: CrossAxisAlignment.start,
                          children: getLazyPutController.rxModels.map((element) {
                            return Text('我要买${element.name}');
                          }).toList()),
                      const Text("data: getLazyPutController.rxModels1",
                          style: TextStyle(color: Colors.black, fontSize: 20, fontWeight: FontWeight.bold)),
                      Column(
                          crossAxisAlignment: CrossAxisAlignment.start,
                          children: getLazyPutController.rxModels1.map((element) {
                            return Text('我要买${element.name}');
                          }).toList()),
                    ]);
                  }),
              onTap: () {
                getLazyPutController.updateRxModels();
              },
            ),
          ),
          Card(
            margin: const EdgeInsets.only(left: 20, right: 20, bottom: 10, top: 10),
            child: ListTile(
              title: const Text("update updateModel"),
              subtitle: GetX<MyGetLazyPutController>(
                  init: getLazyPutController,
                  initState: (_) {},
                  builder: (_) {
                    return Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
                      Text("data model: ${getLazyPutController.model.value.name}"),
                      Text("data model1: ${getLazyPutController.model1.value.name}"),
                    ]);
                  }),
              onTap: () {
                getLazyPutController.updateModel();
              },
            ),
          ),
          Card(
            margin: const EdgeInsets.only(left: 20, right: 20, bottom: 10, top: 10),
            child: ListTile(
              title: const Text("update updateIsTrue"),
              subtitle: GetX<MyGetLazyPutController>(
                  init: getLazyPutController,
                  initState: (_) {},
                  builder: (_) {
                    return Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
                      Text("data isTrue: ${getLazyPutController.isTrue.value}"),
                      Text("data isTrue1: ${getLazyPutController.isTrue1.value}"),
                    ]);
                  }),
              onTap: () {
                getLazyPutController.updateIsTrue();
              },
            ),
          ),
        ],
      )),
    );
  }
}
